package com.flong.selenium;


import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;


public class DemoSelenium2 {

	public static ChromeDriver driver;
	public static String url = "http://www.365yg.com/ch/subv_society/";
	
    static {
    	//http://blog.csdn.net/aerchi/article/details/8055913
    	//设置浏览器启动环境变量
    	System.setProperty("webdriver.chrome.driver", "c:\\Python27\\chromedriver.exe");
    	driver = new ChromeDriver();
    	driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);//SECONDS是秒的意思
    }
    
 
    
    public static void main(String[] args) throws IOException, Exception {
    	driver.navigate().to(url);
		if(isAlertPresent()){
			driver.switchTo().alert().accept();
		}
		driver.manage().window().maximize();
		
		
		WebElement findElement = driver.findElement(By.id("header"));
		System.out.println(findElement.getText());
		
    	
    	driver.close();
    	driver.quit();
    	
    }

    
    protected static boolean isAlertPresent() {
        try {
          driver.switchTo().alert();
          return true;
        } catch (NoAlertPresentException e) {
          return false;
        }
      }
}